﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using XnaCanvas;

using matrix = Microsoft.Xna.Framework.Matrix;
using math = Microsoft.Xna.Framework.MathHelper;
using Slex;

namespace Devplatform {
    public partial class XcTest1 : UserControl {
        public XcTest1() {
            InitializeComponent();
            this.Loaded += XcTest1_Loaded;
            this.Unloaded += XcTest1_Unloaded;
        }

        void XcTest1_Unloaded(object sender, RoutedEventArgs e) {
            xc.End();
        }

        XObject xo;
        XSence xs;
        void XcTest1_Loaded(object sender, RoutedEventArgs e) {
            this.xc.Trigger.FrameRefresh += Trigger_FrameRefresh;
            this.xc.Trigger.MouseEnterState += Trigger_MouseEnterState;
            xc.Begin();
            this.xc.Children[xc.Trigger.Csn].Add("aaa");
            xs = xc.Children[xc.Trigger.Csn];
            xo = xs["aaa"];
            xo.SetColor(20f, 88f, 35.3f, 199.2f);
            //
            xo.Create(r => 1, h => 1, new[] { 0.0d, math.Pi / 2, math.Pi, 3 * math.Pi / 2 }, new[] { 0d, 1.0d });
            xs.SetCamera(new Vector3(0, 0, 10f), Vector3.Zero, Vector3.Up, (float)Math.PI / 3f, 800f / 600f, 1, 1000);
        }


        void Trigger_FrameRefresh(XTrigger sender) {
            //在这里 写 xo的 旋转
            xo.World *= matrix.CreateRotationX(.03f);
            xo.World *= matrix.CreateRotationY(.03f);
            xo.World *= matrix.CreateRotationZ(.03f);
        }

        void Trigger_MouseEnterState(XnaCanvas.XTrigger sender) {
            if (sender.IsMouseEnter) {
                xc.Background = Brushs.Black.ToBrush();

            } else {
                xc.Background = Brushs.Bisque.ToBrush();

            }
        }
    }
}
